<?php
/**
 * Author: Administrator
 * Date: 2022/7/16 23:31
 */

namespace DesignPatterns\Creation\SimpleFactory;


class ConcreteFactory
{
    protected $vehicleTypes = [
        'bicycle' => Bicycle::class,
        'scooter' => Scooter::class,
    ];

    public function createVehicle ($type, ...$args) {
        if (!array_key_exists($type, $this->vehicleTypes)) {
            throw new \InvalidArgumentException('Invalid vehicle type '.$type);
        }
        return new $this->vehicleTypes[$type](...$args);
    }

}